package datastruct;

import java.util.Stack;

public class MinStack155 {
    static class MinStack {
        Stack<Integer> stack;
        Stack<Integer> minStack;

        public MinStack() {
            stack = new Stack<>();
            minStack = new Stack<>();
        }

        public void push(int val) {
            int oldMin = minStack.isEmpty() ? Integer.MAX_VALUE: minStack.peek();
            int newMin = Math.min(oldMin, val);
            stack.push(val);
            minStack.push(newMin);
        }

        public void pop() {
            stack.pop();
            minStack.pop();
        }

        public int top() {
            return stack.peek();
        }

        public int getMin() {
            return minStack.peek();
        }
    }
}
